package com.nyist.diseasepreventionserver.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@Data
@Entity
@Table
public class User extends Base implements Serializable{
    @Column(length = 20,nullable = false)
    private String userName;

    @Column(columnDefinition="int(18)",nullable = false)
    private Integer userSid;

    @Column(length = 20,nullable = false)
    private String userPassword;

    @Column(length = 20,nullable = false)
    private String name;

    @Column(length = 20,nullable = false)
    private String phone;

    //一个用户拥有多个角色，一个角色也可以拥有多个用户\
    @ManyToMany(fetch = FetchType.EAGER) //立即从数据库中加载数据
    @JoinTable(name = "UserPower",joinColumns = {@JoinColumn(name = "uid")},inverseJoinColumns = @JoinColumn(name = "roleId"))
    private List<Role> roles; //一个用户拥有多个角色

    @OneToOne(fetch=FetchType.LAZY,cascade = CascadeType.ALL)
    @JoinColumn(name = "UserHealth",referencedColumnName = "id")
    private HealthDaily healthDaily;
}
